package com.ziyueyuwen.xiniao.controller.dingtalk;

import com.suyeer.basic.util.HttpResUtil;
import com.ziyueyuwen.xiniao.base.HttpResContent;
import com.ziyueyuwen.xiniao.service.ThirdPartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static com.ziyueyuwen.xiniao.base.BaseUtil.saveErrorMsgAndData;
import static com.ziyueyuwen.xiniao.base.BaseUtil.saveSuccessMsgAndData;

/**
 * @author wancheng  on 2018/12/19.
 */
@Controller
@RequestMapping("/dingtalk")
public class DingTalkController {

    @Autowired
    ThirdPartService thirdPartService;

    @RequestMapping(value = "/load_ding_talk_user.do")
    public void getAllStudent(HttpServletRequest request,
                              HttpServletResponse response) {
        HttpResContent<Boolean> hrc = new HttpResContent<>(request, response);
        hrc.setFuncDes("加载钉钉数据");
        try {
            thirdPartService.loadDingTalkUser();
            saveSuccessMsgAndData(hrc, true);
        } catch (Exception e) {
            e.printStackTrace();
            saveErrorMsgAndData(hrc, e);
        } finally {
            HttpResUtil.writeResult(hrc, true);
        }
    }
}
